﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using com.lover.astd.common.config;
using com.lover.astd.common.model;
using com.lover.astd.common.model.enumer;
using com.lover.astd.common;

namespace com.lover.astd.game.ui.server.impl.economy
{
    class ImposeServer : LogicServer
    {
        public ImposeServer(MainForm frm) { _mainForm = frm; ServerName = ConfigStrings.S_Impose; ServerReadableName = ConfigStrings.SR_Impose; }
        public override void renderSettings()
        {
            MainForm frm = _mainForm;
            Dictionary<string, string> conf = getConfig(ServerName);
            if (conf.Count == 0) return;
            frm.chk_impose_enable.Checked = conf.ContainsKey(ConfigStrings.enabled) && conf[ConfigStrings.enabled].ToLower().Equals("true");
            if (conf.ContainsKey(ConfigStrings.impose_reserve))
            {
                int impose_reserve = 0;
                Int32.TryParse(conf[ConfigStrings.impose_reserve], out impose_reserve);
                frm.num_impose_reserve.Value = impose_reserve;
            }
            if (conf.ContainsKey(ConfigStrings.impose_loyalty))
            {
                int impose_loyalty = 0;
                Int32.TryParse(conf[ConfigStrings.impose_loyalty], out impose_loyalty);
                frm.num_impose_loyalty.Value = impose_loyalty;
            }
            if (conf.ContainsKey(ConfigStrings.force_impose_gold))
            {
                int force_impose_gold = 0;
                Int32.TryParse(conf[ConfigStrings.force_impose_gold], out force_impose_gold);
                frm.num_force_impose_gold.Value = force_impose_gold;
            }
        }
        public override void saveSettings()
        {
            MainForm frm = _mainForm;
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, frm.chk_impose_enable.Checked.ToString());
            conf.setConfig(ServerName, ConfigStrings.impose_reserve, frm.num_impose_reserve.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.impose_loyalty, frm.num_impose_loyalty.Value.ToString());
            conf.setConfig(ServerName, ConfigStrings.force_impose_gold, frm.num_force_impose_gold.Value.ToString());
        }
        public override void loadDefaultSettings()
        {
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, "true");
            conf.setConfig(ServerName, ConfigStrings.impose_reserve, "35");
            conf.setConfig(ServerName, ConfigStrings.impose_loyalty, "85");
            conf.setConfig(ServerName, ConfigStrings.force_impose_gold, "2");
            renderSettings();
        }
    }
}
